package com.abc.cloud.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.abc.cloud.common.utils.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.abc.cloud.entity.SensitiveWordEntity;
import com.abc.cloud.service.SensitiveWordService;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Result;



/**
 * 敏感词汇表
 *
 * @author LiJunXi
 * @email 2770063826@qq.com
 * @date 2023-10-27 13:09:54
 */
@RestController
@RequestMapping("cloud/sensitiveword")
public class SensitiveWordController {
    @Autowired
    private SensitiveWordService sensitiveWordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
//        PageUtil page = sensitiveWordService.queryPage(params);
//        return Result.success(page, "page");
        PageUtil pageUtil = sensitiveWordService.getWordList(params);
        return Result.success(pageUtil, "success");
    }






    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		SensitiveWordEntity sensitiveWord = sensitiveWordService.getById(id);

        return Result.success(sensitiveWord, "sensitiveWord");
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody SensitiveWordEntity sensitiveWord){
        Long userId = UserHolder.getUser().getId();

        sensitiveWord.setUserId(userId);
        sensitiveWord.setCreateTime(new Date());
        sensitiveWord.setUpdateTime(new Date());
        sensitiveWord.setStatus(1);
		sensitiveWordService.save(sensitiveWord);
        return Result.success(null, "");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody SensitiveWordEntity sensitiveWord){

            sensitiveWord.setUpdateTime(new Date());
		sensitiveWordService.updateById(sensitiveWord);
        return Result.success(null, "");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		sensitiveWordService.removeByIds(Arrays.asList(ids));
        return Result.success(null, "");
    }



}
